<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@include file="/pageRc/common/common.jsp"%>

<!DOCTYPE html>
<html lang="en" style="overflow-x: hidden">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport"
	content="initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="msapplication-tap-highlight" content="no">

<link rel="stylesheet" href="<%=commonPath%>/pageRc/layui/css/layui.css"
	media="all">
<script type="text/javascript"
	src="<%=commonPath%>/pageRc/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript"
	src="<%=commonPath%>/pageRc/common/utils.js"></script>
<script type="text/javascript"
	src="<%=commonPath%>/pageRc/common/msgTool.js"></script>
<script type="text/javascript"
	src="<%=commonPath%>/pageRc/layui/layui.js"></script>
<script type="text/javascript"
	src="<%=commonPath%>/pageRc/js/num-alignment.js"></script>

<title>产能分配</title>

<script>
	$(function(){

 	})
	//注意：选项卡 依赖 element 模块，否则无法进行工能性操作
	layui.use('element', function() {
		var element = layui.element();

		//…
	});
</script>
<jsp:include page="publicMethod.jsp" />
</head>
<body class="layui-main" style="width: 100%;">
		<input type="hidden" value="${bsCapacity.needId}" id="needId">
		<blockquote class="layui-elem-quote">&nbsp;&nbsp;&nbsp;${bsCapacity.needNo}&nbsp;&nbsp;${bsCapacity.needName}总人月：<span>${bsCapacity.renyue}</span>待分配：<span>${bsCapacity.unWorkload}</span></blockquote>
		<fieldset class="layui-elem-field">
		<legend>产能分配</legend>
		<form id="createMsgForm1" name="createMsgForm1" class="layui-form"
			action="">
			<div class="layui-form-item" id="dateDiv1">
				<div class="layui-inline">
					<table class="layui-table" lay-even="" lay-skin="line"
						style="text-align: center;width: 100%;">
						<colgroup align="center">
							<col width="10%">
							<col width="15%">
							<col width="15%">
							<col width="15%">
							<col width="15%">
							<col width="6%">
						</colgroup>
						<thead>
							<tr>
								<th>姓名</th>
								<th>已报工天数</th>
								<th>已分配工作量</th>
								<th>分配工作量</th>
								<th>时间区间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody id="detailDiv1">

						</tbody>
						<c:forEach begin="0"   varStatus="status" items="${userInfoList}" var="x">
						 <tr align="left">
						   <td>${x.userName==undefined?'':x.userName}</td>
						   <td>${x.sumHappenDate==undefined?'':x.sumHappenDate}</td>
						   <td>${x.workload==undefined?'':x.workload}</td>
						   <td><input id="${x.userName}" class="alignment" data-edit="true" data-step="0.1" data-min="-999" data-max="999" data-digit="2" value="0.00"/></td>
						   <td><input class="layui-input" id="" value="" onclick="layui.laydate({elem: this, istime: true, format: 'YYYYMMDD'})"></td>
						   <td><button  class="layui-btn" type="button" onclick="assign('${x.userId}',this)">确定</button></td>
 						 </tr>
 						 </c:forEach>
					</table>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<div id="laypageDiv1"></div>
				</div>
			</div><button style="margin: 0px;"></button>
		</form>
		</fieldset>
		
		<fieldset class="layui-elem-field">
		<legend>历史记录</legend>
		<form id="createMsgForm2" name="createMsgForm2" class="layui-form"
			action="">
			<div class="layui-form-item" id="dateDiv2">
				<div class="layui-inline">
					<table class="layui-table" lay-even="" lay-skin="line"
						style="text-align: center;width: 100%;">
						<colgroup align="center">
							<col width="15%">
							<col width="15%">
							<col width="15%">
						</colgroup>
						<thead>
							<tr>
								<th>姓名</th>
								<th>已分配工作量</th>
								<th>月份</th>
							</tr>
						</thead>
						<tbody id="detailDiv2">

						</tbody>
						<c:forEach begin="0"   varStatus="status" items="${assignCapacityHistory}" var="x">
						 <tr align="left">
								   <td>${x.userName==undefined?'':x.userName}</td>
								   <td>${x.workload==undefined?'':x.workload}</td> 
								   <td>${x.months==undefined?'':x.months}</td>
 						 </tr>
 						 </c:forEach>
					</table>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<div id="laypageDiv2"></div>
				</div>
			</div><button style="margin: 0px;"></button>
		</form>
		</fieldset>
	</div>
	<input id="totalNum1" type="hidden" name="totalNum1" >
	<input id="totalNum2" type="hidden" name="totalNum2" >
</body>
<script type="text/javascript">
// 初始化
alignmentFns.initialize();
// 销毁
alignmentFns.destroy();

alignmentFns.initialize();

var path="<%=commonPath%>";
	var msg = new msgTool();
	layui.use([ 'form', 'layer', 'laytpl', 'laypage', 'laydate' ],
	function() {
	var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
	var form = layui.form(), layer = layui.layer, laypage = layui.laypage, laytpl = layui.laytpl;
	var active = {}
	$('.layui-btn').on('click',function() {
		var othis = $(this), method = othis.data('method');
		active[method] ? active[method].call(this,othis) : '';
	});
});
	 function flush(){
	        $('#doSearchSum').click();
	    }
	 //确定
	 function assign(userId,thisParam) {
		 var assignWork = $(thisParam).closest('tr').find('td:eq(3)').find('input').val();
		 var assignDate = $(thisParam).closest('tr').find('td:eq(4)').find('input').val();
		 var needId = $("#needId").val();
		 var index = parent.layer.getFrameIndex(window.name); //获取当前窗体索引
		var dataObj = {
				 		"needId": needId,
  						"userId" : userId,
  						"assignWork" : assignWork,
  						"assignDate" : assignDate
  					};
		
		var unWorkload=${bsCapacity.unWorkload};
		if(assignWork<=unWorkload){//判断录入的金额和是否大于评估工时
			  msg.sendMsg("/page/capacity/insertCapacity.do", dataObj, function (data) {
	                layer.alert("分配成功！", function () {
	                    window.parent.flush();
	                    parent.layer.close(index); //执行关闭
	                });
	            });
			  
		}else{
			alert("没有足够的工作量可分配");
		}
	 }
</script>

</html>